aboutsummaryrefslogtreecommitdiff
path: root/src/routes/user/[user]/+page.svelte
blob: c64237546a624bbd65ee66b0dcdd47f33142c5bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script lang="ts">
	import { user, type User } from '$lib/AniList/user';
	import HeadTitle from '$lib/HeadTitle.svelte';
	import { estimatedDayReading } from '$lib/Media/Manga/time';
	import { onMount } from 'svelte';

	export let data;

	let userData: User | undefined = undefined;

	onMount(() => {
		user(data.username).then((profile) => {
			userData = profile;
		});
	});

	// 8.5827814569536423841e0
</script>

<HeadTitle route={`${data.username}'s Profile`} path={`/user/${data.username}`} />

<div class="card">
	{#if userData === null}
		Could not load user profile for <a
			href={`https://anilist.co/user/${data.username}`}
			target="_blank">@{data.username}</a
		>.

		<p />

		Does this user exist?
	{:else if userData === undefined}
		Loading user ... 50%
	{:else}
		<div class="user-grid">
			<a
				href={`https://anilist.co/user/${userData.name}`}
				target="_blank"
				title={String(userData.id)}
			>
				<img src={userData.avatar.large} alt="" width="100vw" id="avatar" />
			</a>

			<div>
				<p>
					<a
						href={`https://anilist.co/user/${userData.name}`}
						target="_blank"
						title={String(userData.id)}>@{userData.name}</a
					>
					<span class="click-item">•</span> <a href={`/user/${userData.name}/badges`}>Badge Wall</a>
				</p>

				{data.username} has watched {(userData.statistics.anime.minutesWatched / 60 / 24).toFixed(
					1
				)} days of anime and read
				{estimatedDayReading(userData.statistics.manga.chaptersRead).toFixed(1)} days of manga.

				<p />

				{data.username} has collected {#await fetch(`/api/badges?id=${userData.id}`)}
					...
				{:then badges}
					{#await badges.json()}
						...
					{:then badges}
						{badges.length}
					{:catch}
						?
					{/await}
				{:catch}
					?
				{/await}
				badges using Badge Wall.
			</div>
		</div>
	{/if}
</div>

<style>
	.user-grid {
		display: flex;
		flex-wrap: wrap;
		column-gap: 1.5em;
	}

	#avatar {
		margin-top: 0.5em;
		padding-bottom: 0.5em;
	}

	.click-item {
		margin: 0 0.625rem;
	}
</style>